package com.android.component;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

public class IntentTest extends Activity implements OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.intent);

        findViewById(R.id.make_call).setOnClickListener(this);
        findViewById(R.id.send_mail).setOnClickListener(this);
        findViewById(R.id.send_sms).setOnClickListener(this);
        findViewById(R.id.open_url).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.make_call) {

            Intent i = new Intent(Intent.ACTION_CALL);
            i.setData(Uri.parse("tel:1234566"));
            startActivity(i);
        } else if (v.getId() == R.id.send_mail) {
            Intent emailIntent = new Intent(Intent.ACTION_SEND);

            String subject = "Hi!";
            String body = "hello from android....";

            String[] extra = new String[] { "aaa@bbb.com" };

            emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
            emailIntent.putExtra(Intent.EXTRA_TEXT, body);
            emailIntent.putExtra(Intent.EXTRA_EMAIL, extra);
            emailIntent.setType("message/rfc822");

            startActivity(emailIntent);
        } else if (v.getId() == R.id.send_sms) {
            Log.d("", "send sms");
            Intent i = new Intent(Intent.ACTION_SENDTO);
            i.setData(Uri.parse("smsto:1234566"));
            i.putExtra("sms_body", ":短信内容 ");
            startActivity(i);
        } else if (v.getId() == R.id.open_url) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse("http://www.baidu.com"));
            startActivity(i);
        }
    }
}
